SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[incumbencias] @cargo as int,@asignatura as int  AS
SET NOCOUNT ON
declare @cargogenerico as int,@asignaturagenerica as int, @grupo as int
declare @i as integer,@j as integer

set @i=0
set @j=0

declare CargoAsignatura cursor SCROLL for 
	select cargogenerico,asignaturagenerica from tb_incumbencias where  grupoincumbencia=10 and cargogenerico < 1000  
	open CargoAsignatura
	fetch first  from CargoAsignatura  into @CargoGenerico,@AsignaturaGenerica 
--	fetch next from CargoAsignatura into @CargoGenerico,@AsignaturaGenerica 

declare GrupoInc cursor SCROLL for
	select distinct grupoincumbencia from tb_incumbencias where grupoincumbencia <> 10 and grupoincumbencia <>99  and cargogenerico < 1000 order by grupoincumbencia
	open GrupoInc


while @@FETCH_STATUS = 0
begin
	fetch first from GrupoInc  into @grupo
--	fetch next from GrupoInc into @grupo
	while @@FETCH_STATUS = 0
	begin
		print 'insert tb_incumbencias (grupo,cargo,asignatura)  : values( ' + cast(@grupo as varchar) +'  ' + cast(@CargoGenerico as varchar) +'  ' + cast(@AsignaturaGenerica as varchar) + ')'
--		insert tb_incumbencias (grupoincumbencia,cargoGenerico,asignaturaGenerica)  values(@grupo,@cargoGenerico,@AsignaturaGenerica)
		fetch next from GrupoInc into @grupo
		set @i=@i+1
	end
	fetch next from CargoAsignatura into @CargoGenerico,@AsignaturaGenerica 
	set @j=@j+1
end

close Cargoasignatura
deallocate Cargoasignatura

close GrupoInc
deallocate GrupoInc

print ' Cantidad de incumbencias afectadas ' + cast(@i as varchar)
print ' Cantidad de Cargos ,Asignaturas  ' + cast(@j as varchar)





/* esto es para relacionar todo polimodal con todos los cargos_asignaturas de polimodal
idem para egb pero cambiando el grupo 565 por 564

insert tb_incumbencias (grupoincumbencia,cargoGenerico,asignaturaGenerica)
select 565,cargo_definitivo,asignatura_definitiva from mig.dbo.cargos_asignaturas_ceprode2 
where cargo_definitivo <>0 and cargo_definitivo > 1000 order by 1,2
*/
GO
